﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace WPFSample.MeasureSample
{
    class MyPanelParent : Panel
    {
        protected override Size MeasureOverride(Size availableSize)
        {
            foreach (UIElement item in this.InternalChildren)
            {
                item.Measure(new Size(availableSize.Width / 2, availableSize.Height / 2));//这里是入口
            }

            return availableSize;
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            double x = 0;
            foreach (UIElement item in this.InternalChildren)
            {
                item.Arrange(new Rect(x, 0, item.DesiredSize.Width, item.DesiredSize.Height));
                x += finalSize.Width / 2;
            }

            return finalSize;
        }
    }
}
